package com.yndsoft.jc.supplier.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yndsoft.jc.R;
import com.yndsoft.jc.supplier.comment.CommentActivity;
import com.yndsoft.jc.supplier.hr.HrActivity;
import com.yndsoft.jc.supplier.info.PersonalActivity;
import com.yndsoft.jc.supplier.info.SupplierInfoActivity;
import com.yndsoft.jc.supplier.model.SudokuModel;
import com.yndsoft.jc.supplier.order.OrderActivity;
import com.yndsoft.jc.supplier.order.SecondOrderActivity;
import com.yndsoft.jc.supplier.perfect.PerfectActivity;
import com.yndsoft.jc.supplier.utils.Constants;
import com.yndsoft.jc.supplier.utils.ScreenUtil;
import com.yndsoft.jc.supplier.utils.ToastUtil;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerAdapter;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerHolder;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerListener;
import com.yndsoft.jc.ui.memberpage.login.ChangePswActivity;
import com.yndsoft.jc.ui.memberpage.setting.SettingActivity;

import java.util.List;

public class SudokuAdapter extends RecyclerAdapter<SudokuModel> implements RecyclerListener.OnClickListener<RecyclerHolder> {

    private String tag;

    public SudokuAdapter(Context context, List<SudokuModel> data, String tag) {
        super(context, data, R.layout.item_sudoku);
        this.tag = tag;
    }

    @Override
    public void convert(RecyclerHolder holder, SudokuModel model) {

        LinearLayout sudokuRoot = holder.findViewById(R.id.sudoku_root);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
        );
        int i = ScreenUtil.getScreenWidth(mContext) / 3;
        params.width = i;
        params.height = i;
        sudokuRoot.setLayoutParams(params);

        TextView sudokuItem = holder.findViewById(R.id.sudoku_item);
        sudokuItem.setText(model.getName() != null ? model.getName() : "");
        Drawable drawable = mContext.getResources().getDrawable(model.getResId());
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        sudokuItem.setCompoundDrawables(null, drawable, null, null);
        holder.setOnClickListener(this, R.id.sudoku_root);
    }

    @Override
    public void onClick(View v, int position, RecyclerHolder holder) {
        switch (position) {
            case 0:
                setZero();
                break;
            case 1:
                setOne();
                break;
            case 2:
                setTwo();
                break;
            case 3:
                HrActivity.start(mContext, Constants.HOLIDAY); // 假期列表
                break;
            case 4:
                SupplierInfoActivity.start(mContext); // 机构资料
                break;
            case 5:
                Intent intent = new Intent(mContext, ChangePswActivity.class);
                intent.putExtra(Constants.TAG, Constants.SUPPLIER);
                mContext.startActivity(intent); // 修改密码
                break;
            case 6:
                HrActivity.start(mContext, Constants.CONTACT); // 联系人
                break;
            case 7:
                HrActivity.start(mContext, Constants.ENTRY); // 录入员
                break;
            case 8:
                HrActivity.start(mContext, Constants.SIGN); // 审核员
                break;
            case 9:
                mContext.startActivity(new Intent(mContext, SettingActivity.class)); // 设置
                break;
        }
    }

    private void setZero() {
        if (tag != null) {
            if (tag.equals(Constants.SUPPLIER)) {
                OrderActivity.start(mContext); // 机构订单列表
            }
            if (tag.equals(Constants.SIGN)) {
                SecondOrderActivity.start(mContext, Constants.SIGN); // 审核订单列表
            }
            if (tag.equals(Constants.ENTRY)) {
                SecondOrderActivity.start(mContext, Constants.ENTRY); // 录入订单列表
            }
        }
    }

    private void setOne() {
        if (tag != null) {
            if (tag.equals(Constants.SUPPLIER)) {
                CommentActivity.start(mContext); // 机构评价列表
            }
            if (tag.equals(Constants.SIGN) || tag.equals(Constants.ENTRY)) {
                mContext.startActivity(new Intent(mContext, SettingActivity.class));
            }
//            if (tag.equals(Constants.SIGN)) {
//                PersonalActivity.start(mContext, Constants.SIGN); // 审核个人资料
//            }
//            if (tag.equals(Constants.ENTRY)) {
//                PersonalActivity.start(mContext, Constants.ENTRY); // 录入个人资料
//            }
        }
    }

    private void setTwo() {
        if (tag != null) {
            if (tag.equals(Constants.SUPPLIER)) {
                PerfectActivity.start(mContext); // 机构完善项目
            }
//            if (tag.equals(Constants.SIGN)) {
//                ToastUtil.show(mContext, "审核设置");
//            }
//            if (tag.equals(Constants.ENTRY)) {
//                ToastUtil.show(mContext, "录入设置");
//            }
        }
    }
}